<template>
  <div class="example-container">
    <h3>日期选择器组件示例</h3>
    
    <div class="demo-section">
      <h4>默认选项</h4>
      <DateTabSelector v-model="dateRange1" />
      <div class="result">
        <p>选择结果：{{ formatDateRange(dateRange1) }}</p>
      </div>
    </div>
    
    <div class="demo-section">
      <h4>自定义选项</h4>
      <DateTabSelector v-model="dateRange2" :options="customOptions" />
      <div class="result">
        <p>选择结果：{{ formatDateRange(dateRange2) }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import DateTabSelector from './DateTabSelector.vue'
import moment from 'moment'

export default {
  name: 'ExampleUsage',
  components: {
    DateTabSelector
  },
  data() {
    return {
      dateRange1: [],
      dateRange2: [],
      customOptions: [
        {
          key: 'day3',
          name: '近3天',
          getValue: () => {
            const start = moment().subtract(2, 'days').startOf('day')
            const end = moment().endOf('day')
            return [start.format('YYYY-MM-DD'), end.format('YYYY-MM-DD')]
          }
        },
        {
          key: 'week2',
          name: '近2周',
          getValue: () => {
            const start = moment().subtract(13, 'days').startOf('day')
            const end = moment().endOf('day')
            return [start.format('YYYY-MM-DD'), end.format('YYYY-MM-DD')]
          }
        },
        {
          key: 'quarter',
          name: '本季度',
          getValue: () => {
            const start = moment().startOf('quarter')
            const end = moment().endOf('day')
            return [start.format('YYYY-MM-DD'), end.format('YYYY-MM-DD')]
          }
        },
        {
          key: 'halfYear',
          name: '半年',
          getValue: () => {
            const start = moment().subtract(6, 'months').startOf('day')
            const end = moment().endOf('day')
            return [start.format('YYYY-MM-DD'), end.format('YYYY-MM-DD')]
          }
        }
      ]
    }
  },
  methods: {
    formatDateRange(range) {
      if (!range || range.length < 2) {
        return '未选择';
      }
      
      const startDate = range[0];
      const endDate = range[1];
      const tabKey = range.length > 2 ? range[2] : '无';
      
      return `开始时间: ${startDate}, 结束时间: ${endDate}, 选项: ${tabKey}`;
    }
  }
}
</script>

<style lang="scss" scoped>
.example-container {
  max-width: 800px;
  margin: 20px auto;
  padding: 20px;
  background-color: #f5f5f5;
  border-radius: 8px;
  
  h3 {
    color: #333;
    text-align: center;
    margin-bottom: 20px;
  }
  
  .demo-section {
    margin-bottom: 30px;
    padding: 15px;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    
    h4 {
      color: #666;
      margin-bottom: 10px;
    }
    
    .result {
      margin-top: 15px;
      padding: 10px;
      background-color: #f9f9f9;
      border-radius: 4px;
      font-size: 14px;
      
      p {
        margin: 0;
        color: #333;
      }
    }
  }
}
</style> 